package org.study.opensearch.boot.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.study.opensearch.boot.model.Product;
import org.study.opensearch.boot.repository.ProductRepository;

import java.math.BigDecimal;
import java.util.List;

/**
 * 作用描述
 *
 * @author doveylovey
 * @version v1.0.0
 * @email 1135782208@qq.com
 * @date 2025年05月09日
 */
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RestController
@RequestMapping("/marketplace")
public class ProductController {
    private final ProductRepository repository;

    @GetMapping(value = "/search", produces = MediaType.APPLICATION_JSON_VALUE)
    public List<Product> search(
            @RequestParam(value = "name", required = false, defaultValue = "") String name,
            @RequestParam(value = "price", required = false, defaultValue = "0.0") BigDecimal price
    ) {
        return repository.findByNameLikeAndPriceGreaterThan(name, price);
    }
}
